﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.Profile;
using umbraco;
using CommerceForUmbraco.profile;
using umbraco.cms.businesslogic.member;
using umbraco.cms.businesslogic.propertytype;
using Commerce.Common;
using System.Text;

namespace CommerceForUmbraco.usercontrols.usercontrols.commerce
{
    public partial class PWOrderDetails : System.Web.UI.UserControl
    {
        public string OrderGUID { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.IsPostBack == false)
            {
                DisplayOrderInfo(this.OrderGUID);
            }
        }

        private void DisplayOrderInfo(string orderGUID)
        {
            Member currentMember = Member.GetCurrentMember();
            if (currentMember == null)
            {
                this.ctrlErrorFeedbackLabel.Text = "Sorry, you must be signed on in order to view your order details.";
                return;
            }

            try
            {
                Order order = OrderController.GetOrder(orderGUID);

                phOrderDetails.Controls.Add(new LiteralControl(order.ToHtml()));
            }
            catch (Exception e)
            {
                this.ctrlErrorFeedbackLabel.Text = String.Format("Error: {0}", e.Message);
            }
        }
    }
}